<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.2</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8"/>
    <link rel="stylesheet" href="/static/css/font.css">
    <link rel="stylesheet" href="/static/css/xadmin.css">
    <script src="/static/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/static/js/xadmin.js"></script>
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body>
<div class="x-nav">
          <span class="layui-breadcrumb">
            <a href="">首页</a>
            <a href="">演示</a>
            <a>
              <cite>导航元素</cite></a>
          </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
</div>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <form class="layui-form layui-col-space5">
                        <div class="layui-inline layui-show-xs-block">
                            <input class="layui-input" autocomplete="off" placeholder="开始日" name="start" id="start">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <input class="layui-input" autocomplete="off" placeholder="截止日" name="end" id="end">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <input type="text" name="username" placeholder="请输入用户名" autocomplete="off"
                                   class="layui-input">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <button class="layui-btn" lay-submit="" lay-filter="search"><i
                                    class="layui-icon">&#xe615;</i></button>
                        </div>
                    </form>
                </div>
                <div class="layui-card-header">
                    <button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon"></i>批量删除
                    </button>
                    <button class="layui-btn" onclick="xadmin.open('添加用户','./admin_add',600,500)"><i class="layui-icon"></i>添加
                    </button>
                </div>
                <table class="layui-hide" id="test" lay-filter="demo"></table>
            </div>
            <!--            <div class="layui-card-body ">-->
            <!--                <div class="page">-->
            <!--                    <div>-->
            <!--                        <a class="prev" href="">&lt;&lt;</a>-->
            <!--                        <a class="num" href="">1</a>-->
            <!--                        <span class="current">2</span>-->
            <!--                        <a class="num" href="">3</a>-->
            <!--                        <a class="num" href="">489</a>-->
            <!--                        <a class="next" href="">&gt;&gt;</a>-->
            <!--                    </div>-->
            <!--                </div>-->
            <!--            </div>-->
        </div>
    </div>
</div>
</div>
</body>

<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit" onclick="xadmin.open('用户编辑','./admin_edit',600,400)">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>

<script>
    layui.use(['table', 'form'], function () {
        var table = layui.table;
        var form = layui.form;
        table.render({
            elem: '#test'
            , url: '/index.php/admin/admin/list1'
            , page: true
            , cellMinWidth: 80 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
            , cols: [[
                {type: 'checkbox'}
                , {field: 'id', width: 100, title: 'ID', sort: true}
                , {field: 'username', width: 100, title: '用户名'}
                , {field: 'role', width: 100, title: '角色'}
                , {field: 'tel', width: 180, title: '电话', sort: true}
                , {field: 'email', width: 180, title: '邮箱'}
                , {
                    field: 'add_time',
                    width: 180,
                    title: '添加时间',
                    templet: "<div>{{layui.util.toDateString(d.add_time, 'yyyy-MM-dd HH:mm:ss')}}</div>"
                }
                , {fixed: 'right', title: '操作', toolbar: '#barDemo', width: 340}
            ]]
        });
        form.on('submit(search)', function (data) {

            var username = data.field.username;
            console.log(username);
            table.reload('test', {
                url: "{:url('admin/admin/admin_like')}"
                , request: {}
                , where: {
                    username: username
                }
            });
            return false;   //表单按钮的js回调函数添加retrun false制止
        });

        table.on('checkbox(demo)', function (obj) {
            console.log(obj)
        });
        //监听工具条
        table.on('tool(demo)', function (obj) {
            var data = obj.data;
            if (obj.event === 'detail') {
                layer.msg('ID：' + data.id + ' 的查看操作');
            } else if (obj.event === 'del') {
                layer.confirm('真的删除行么', function (index) {
                    $.ajax({
                        type: 'get',
                        url: "{:url('admin/admin/admin_delete')}",
                        data: {id: data.id},
                    });
                    obj.del();
                    layer.close(index);
                });
            } else if (obj.event === 'edit') {

                layer.open({
                    title: ['修改数据', 'font-size:18px;'],
                    type: 2,
                    area: ['600px', '400px'], //宽高
                    content: '/index.php/admin/admin/admin_edit',
                    scrollbar: false,
                    success: function (layero, index) {

                        var inp = $(layero).find("iframe").contents().find("#id");
                        inp.val(data.id);

                    }
                });
            }
        });

        var $ = layui.$, active = {
            getCheckData: function () { //获取选中数据
                var checkStatus = table.checkStatus('idTest')
                    , data = checkStatus.data;
                layer.alert(JSON.stringify(data));
            }
            , getCheckLength: function () { //获取选中数目
                var checkStatus = table.checkStatus('idTest')
                    , data = checkStatus.data;
                layer.msg('选中了：' + data.length + ' 个');
            }
            , isAll: function () { //验证是否全选
                var checkStatus = table.checkStatus('idTest');
                layer.msg(checkStatus.isAll ? '全选' : '未全选')
            }
        };

        $('.demoTable .layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });

</script>


<script>


    function delAll(argument) {

        var data = tableCheck.getData();

        layer.confirm('确认要删除吗？' + data, function (index) {
            //捉到所有被选中的，发异步进行删除
            layer.msg('删除成功', {icon: 1});
            $(".layui-form-checked").not('.header').parents('tr').remove();
        });
    }
</script>


</html>